# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, models


class ProductPricelistReport(models.AbstractModel):
    _inherit = 'report.product.report_pricelist'

    @api.model
    def get_meituan_price(self):
        pricelist = self.env['product.pricelist'].search([('id', '=', 2)], limit=1)
        products = self.env['product.product'].search([('sale_ok', '=', True)])

        return [{'ID': product.id,
                 'default_code': product.default_code,
                 'name': product.name,
                 'website_sequence': product.website_sequence,
                 'price': pricelist._get_product_price(product, 1)}
                for product in products]

    @api.model
    def get_rpc_price(self, priceid):
        pricelist = self.env['product.pricelist'].search([('id', '=', priceid)], limit=1)
        products = self.env['product.product'].search([('sale_ok', '=', True)])

        return [{'ID': product.id,
                 'default_code': product.default_code,
                 'name': product.name,
                 'website_sequence': product.website_sequence,
                 'price': pricelist._get_product_price(product, 1)}
                for product in products]

    @api.model
    def get_product_list(self, product_name=None):
        pricelist = self.env['product.pricelist'].search([('id', '=', 2)], limit=1)
        if product_name:
            products = self.env['product.product'].search(
            [('is_published', '=', True), ('sale_ok', '=', True), ('name', 'ilike', product_name)])
        else:
            products = self.env['product.product'].search(
            [('is_published', '=', True), ('sale_ok', '=', True)])
        return [{'ID': product.id,
                 'default_code': product.default_code,
                 'name': product.name,
                 'qty_available': product.qty_available,
                 'website_sequence': product.website_sequence,
                 'price': pricelist._get_product_price(product, 1)}
                for product in products]
